﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;

namespace Infancy.Core.Plugin {
    public abstract class PluginBase : IPlugin {
        public event EventHandler<RegisterRoutingEventArgs> RegisterRouting;

        public event EventHandler<RegisterRoutingEventArgs> UnRegisterRouting;

        #region IPlugin Members

        public virtual void Initialize() {
            OnRegisterRouting(new RegisterRoutingEventArgs(RouteTable.Routes));
        }

        public abstract void Install();

        public virtual void UnInstall() {
            Dispose();
        }

        public abstract PluginExecuteResult Execute(PluginContext context);

        public abstract PluginInfo Info { get; }

        #endregion

        #region IDisposable Members

        public virtual void Dispose() {
            OnUnRegisterRouting(new RegisterRoutingEventArgs(RouteTable.Routes));
        }

        #endregion

        public virtual void OnRegisterRouting(RegisterRoutingEventArgs e) {
            if (RegisterRouting != null)
                RegisterRouting(this, e);
        }

        public virtual void OnUnRegisterRouting(RegisterRoutingEventArgs e) {
            if (UnRegisterRouting != null)
                UnRegisterRouting(this, e);
        }
    }
}
